<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>分单利润</title>
    <% include("/common/common_css_js.html"){} %>
  </head>
  <body>
    <div style="padding-bottom: 5px;">
      <div id="queryForm" class="uc-toolbaroverflow" _borderStyle="border-top:0;">
        <span>分单号：</span><input id="keyBillCode" name="keyBillCode" emptyText="请输入分单号"  class="mini-textbox" selectOnFocus="true" required="false" requiredErrorText="分单号不能为空" />
        <span class="separator"></span>
        <span>分单归属部门:</span>
        <input id="keyAttributionDepartmentId" name="keyAttributionDepartmentId" class="mini-treeselect" style="width:250px;" textField="name" valueField="id" emptyText="请选择..."
               expandOnLoad="2"  virtualScroll="true"
               required="false" allowInput="true" showNullItem="true" nullItemText="请选择..." requiredErrorText="没有选择归属部门"/>
        <span class="separator"></span>
        <span>运输种类:</span><input id="keyTransportSpeciesId" name="keyTransportSpeciesId" class="mini-combobox" style="width:150px;" textField="name" valueField="id" emptyText="请选择..."
                                 required="false" allowInput="false" showNullItem="false" nullItemText="请选择..." requiredErrorText="没有选择运输种类" onvaluechanged="transportSpeciesIdChange" />
        <span class="separator"></span>
        <span>承运方式:</span><input id="keyTransportWayId" name="keyTransportWayId" class="mini-combobox" style="width:150px;" textField="name" valueField="id" emptyText="请选择..."
                                 required="false" allowInput="false" showNullItem="false" nullItemText="请选择..." requiredErrorText="没有选择承运方式"/>
        <div style="margin-top: 5px"></div>
        <span>发货人:</span>
        <div id="keyDeliveryCustomerId" name="keyDeliveryCustomerId" class="mini-autocomplete" style="width:250px;"  popupWidth="1000" textField="name" valueField="id"
             url="${base}/pages/customer_manage/queryDeliveryCustomerByKey"  required="false" requiredErrorText="发货人不能为空"
             searchField="key"
             emptyText="发货人名称">
          <div property="columns">
            <div header="ID" field="id" width="30"></div>
            <div header="客户名称" field="name"></div>
            <div header="客户简称" field="shortName"></div>
            <div header="客户电话" field="phone"></div>
            <div header="客户地址" field="address"></div>
          </div>
        </div>

        <span class="separator"></span>
        <span>收货人:</span>
        <input id="keyReceiveCustomerName" name="keyReceiveCustomerName" style="width:250px;"  emptyText="收货人名称"  class="mini-textbox" selectOnFocus="true" required="false" requiredErrorText="收货人名称不能为空"/>

        <span class="separator"></span>
        <span>提货点:</span>
        <div id="keyPickUpPointId" name="keyPickUpPointId" class="mini-autocomplete" style="width:150px;"  popupWidth="500" textField="name" valueField="id"
             required="false" requiredErrorText="提货点不能为空"
             url="${base}/pages/basic_data_manage/xt_pick_up_point/queryPickUpPointByCondition?cityId="
             searchField="key"
             emptyText="提货点名称">
          <div property="columns">
            <div header="提货点名称" field="name" width="150"></div>
            <div header="提货点电话" field="phone" width="150"></div>
            <div header="提货点地址" field="address" width="200"></div>
          </div>
        </div>
        <span class="separator"></span>
        <span>开单日期：</span>
        <input id="keyOpenBillStartDate" name="keyOpenBillStartDate"  class="mini-datepicker"   format="yyyy-MM-dd"/>--<input id="keyOpenBillEndDate" name="keyOpenBillEndDate" class="mini-datepicker"  format="yyyy-MM-dd"/>


        <div style="margin-top: 5px"></div>

        <% if(so.hasPermission("bNativeBillGrossProfit:query")){%>
        <a class="mini-button" iconCls="icon-search" onclick="searchBill()">查询</a>
        <% } %>

        <% if(so.hasPermission("bNativeBillGrossProfit:queryCndClear")){%>
        <a class="mini-button" iconCls="icon-new" onclick="clearSearch()">清空查询条件</a>
        <% } %>

        <% if(so.hasPermission("bNativeBillGrossProfit:download")){%>
          <span class="separator"></span>
          <#download_grid id="downloadGrid" theGridId="datagrid1" theFileName="分单利润信息表"/>
        <% } %>

      </div>
    </div>


    <div class = "mini-fit">
      <div id="datagrid1" class="mini-datagrid"
           style="width: 100%; height: 100%;"
           url="${base}/pages/master_bill_manage/load/queryNativeBillLoadGrossProfit" idField="id"
           showPager="true" pageSize="20" sizeList="[10,20,30,50,100]"
           allowResize="true"
           showGroupsSummary="true" showSummaryRow="true" summaryPosition="bottom"
           allowSortColumn = "true"
           sortField="createTime"
           sortOrder="desc"
           ondrawsummarycell="summaryRight">
        <div property="columns">
          <div field="open_bill_date" width="140" headerAlign="center" align="center" allowSort="false" dateFormat="yyyy-MM-dd HH:mm:ss" renderer="ondayRenderer">开单日期</div>
          <div field="id" width="80" headerAlign="center" align="center" allowSort="true"  renderer="showNativeBillRender">分单号</div>
          <div field="bill_load_master_bill_ids" width="100" headerAlign="center" align="center" allowSort="true" renderer="showMasterBillRender" >主单号</div>
          <div field="airport_id" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"airport"}' renderer="commonRender">始发机场</div>
          <div field="flight_name" width="140" headerAlign="center" align="center" allowSort="true">班次号</div>
          <div field="dest_city_id" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"city"}' renderer="commonRender">目的市</div>
          <div field="goods_name" width="140" headerAlign="center" align="center" allowSort="true" >货物名称</div>
          <div field="total_number" width="140" headerAlign="center" align="right" allowSort="false">分单件数</div>
          <div field="actual_weight" width="140" headerAlign="center" align="right" allowSort="false" >分单实重</div>
          <div field="settlement_amount" width="140" headerAlign="center" align="right" allowSort="false" >分单结算金额</div>
          <div field="open_bill_delivery_charge" width="140" headerAlign="center" align="right" allowSort="false" >分单开单送货费</div>
          <div field="agent_delivery_charge" width="140" headerAlign="center" align="right" allowSort="false" >分单代理送货费</div>
          <div field="service_charge" width="140" headerAlign="center" align="right" allowSort="false" >分单业务费</div>
          <div field="share_cost" width="140" headerAlign="center" align="right" allowSort="false">分单总成本</div>
          <div field="load_number" width="140" headerAlign="center" align="right" allowSort="false" summaryType="sum">配载件数</div>
          <div field="load_actual_weight" width="140" headerAlign="center" align="right" allowSort="false" summaryType="sum">配载实重</div>
          <div field="load_chargeable_weight" width="140" headerAlign="center" align="right" allowSort="false" summaryType="sum">配载计重</div>
          <div field="load_volume" width="140" headerAlign="center" align="right" allowSort="false" summaryType="sum">配载体积</div>
          <div field="share_transport_cost_amount" width="140" headerAlign="center" align="right" allowSort="false" summaryType="sum">配载分摊运输成本</div>
          <div field="share_ground_amount" width="140" headerAlign="center" align="right" allowSort="false" summaryType="sum">配载分摊地面成本</div>
          <div field="share_airlines_add_cost_amount" width="140" headerAlign="center" align="right" allowSort="false" summaryType="sum">配载分摊附加费成本</div>
          <div field="share_other_charges_amount" width="140" headerAlign="center" align="right" allowSort="false" summaryType="sum">配载分摊其他成本</div>
          <div field="share_total_cost_amount" width="140" headerAlign="center" align="right" allowSort="false" summaryType="sum">配载分摊总成本</div>
<!--          <div field="gross_profit" width="140" headerAlign="center" align="right" allowSort="false" >分单利润</div>-->
          <div field="pull_cost_share_amount" width="140" headerAlign="center" align="right" allowSort="false" >分单拉货分摊成本</div>
          <div field="total_share_cost" width="140" headerAlign="center" align="right" allowSort="false" >分单总成本</div>
          <div field="settlement_gross_profit" width="140" headerAlign="center" align="right" allowSort="false" >分单结算利润</div>
          <div field="airlines_id" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"airlines"}' renderer="commonRender">航空公司</div>
          <div field="delivery_customer_name" width="140" headerAlign="center" align="center" allowSort="true">发货人</div>
          <div field="delivery_customer_saleman_id" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysUser"}' renderer="commonRender">业务员</div>
          <div field="share_total_cost_comment" width="140" headerAlign="center" align="center" allowSort="true">配载分摊成本说明</div>
          <div field="share_cost_comment" width="140" headerAlign="center" align="center" allowSort="true" >分单成本说明</div>
        </div>
      </div>
    </div>


    <script type="text/javascript">

      mini.parse();

      //keyAttributionDepartmentId   keyTransportSpeciesId  keyTransportWayId  keyDeliveryCustomerId  keyPickUpPointId  keyPickUpGoodsWayId

      let keyAttributionDepartmentId = mini.get("keyAttributionDepartmentId");
      let keyTransportSpeciesId = mini.get("keyTransportSpeciesId");
      let keyTransportWayId = mini.get("keyTransportWayId");

      let keyPickUpPointId = mini.get("keyPickUpPointId");


      let grid = mini.get("datagrid1");

      $(function () {

        let keyAttributionDepartmentIdJsonData = commonRenderDropList("department");
        keyAttributionDepartmentId.loadList(keyAttributionDepartmentIdJsonData,"id","pid");

        // 运输种类下拉列表
        let transportSpeciesIdJsonData=commonRenderSysDicDropListByKey("sysDic","XT_DIC_TRANSPORT_SPECIES");
        keyTransportSpeciesId.load(transportSpeciesIdJsonData);

        // 承运方式下拉列表
        let transportWayIdJsonData=commonRenderSysDicDropListByKey("sysDic","XT_DIC_TRANSPORT_WAY");
        keyTransportWayId.load(transportWayIdJsonData);

        // 加载列表数据
        searchBill();
      });

      function clearSearch(){
        let form = new mini.Form("#queryForm");
        form.clear();
      }

      /**
       * 根据查询条件查询分单
       */
      function searchBill(){
        let form = new mini.Form("#queryForm");
        let data = form.getData(true);
        data.keyShareCostCommentLength = 10; // 补上一个成本分摊说明长度不小于10个字符的条件
        grid.load(data);
      }

      function showNativeBillRender(e){
        let nativeBillId = e.value;
        let htmlStr = "<a href='javascript:void(0);' onclick='showViewNativeBill(\""+ nativeBillId +"\")'>" + nativeBillId + "</a>";
        return htmlStr;
      }

      function showViewNativeBill(nativeBillId){
        let tabUrl="${base}/pages/native_bill_manage/showUpdateBill?opType=view&id=" + nativeBillId;
        parent.window.addTabToMainPage("分单查看","分单查看",tabUrl);
      }

      // 展示主单号时显示其超链接
      function showMasterBillRender(e){
        let masterBillId = e.value;
        let masterBillTypeId = e.record.masterBillTypeId;
        let htmlStr = "<a href='javascript:void(0);' onclick='showViewMasterBill(\""+ masterBillId +"\"," + masterBillTypeId + ")'>" + masterBillId + "</a>";

        return htmlStr;
      }

      let masterBillType={air:261,auto:262}

      function showViewMasterBill(masterBillId,masterBillTypeId){
        // 根据类型打开相应的编辑页面，在编辑页面上做些处理，把保存按钮给隐藏了
        let tabUrl;
        let title;
        if(masterBillTypeId==masterBillType.air){
          title = "空运主单";
          tabUrl="${base}/pages/master_bill_manage/flight/showUpdateMasterBill?opType=view&id=" + masterBillId;
        }
        else{
          title = "汽运主单";
          tabUrl=tabUrl="${base}/pages/master_bill_manage/auto/showUpdateMasterBill?opType=view&id=" + masterBillId;
        }

        parent.window.addTabToMainPage(title,title,tabUrl);
      }


      /**
       * 设置底部统计样式
       * @param e
       */
      function summaryRight(e){
        e.cellStyle="text-align:right;color:red;font-size:18px;font-weight:bold";
      }

    </script>


  </body>
</html>